package cn.main.web;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;


/**
 * Author: chengwei
 * Date:   2016/7/14
 * Time:   12:20
 */
public class SpringBean implements ApplicationContextAware{
    private static ApplicationContext applicationContext;
    
    public static <T> T getBean(Class<T> clazz) {
        return applicationContext.getBean(clazz);
    }

    public static <T> T getBean(String clazzName) {
        return (T) applicationContext.getBean(clazzName);
    }
    
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringBean.applicationContext = applicationContext;
    }
}
